package com.flxz.user.controller;

import com.flxz.common.core.controller.BaseController;
import com.flxz.common.core.domain.AjaxResult;
import com.flxz.user.service.IUserCategoryService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;
import java.util.Map;

/**
 * 用户分类Controller
 * 提供收入支出分类查询功能
 */
@RestController
@RequestMapping("/user/categories")
public class UserCategoryController extends BaseController {

    @Autowired
    private IUserCategoryService userCategoryService;

    /**
     * 获取收入分类列表
     */
    @PreAuthorize("@ss.hasRole('common') or @ss.hasPermi('user:category:query')")
    @GetMapping("/income")
    public AjaxResult getIncomeCategories() {
        List<Map<String, Object>> categories = userCategoryService.getIncomeCategories();
        return success(categories);
    }

    /**
     * 获取支出分类列表
     */
    @PreAuthorize("@ss.hasRole('common') or @ss.hasPermi('user:category:query')")
    @GetMapping("/expense")
    public AjaxResult getExpenseCategories() {
        List<Map<String, Object>> categories = userCategoryService.getExpenseCategories();
        return success(categories);
    }

    /**
     * 获取所有分类列表（收入+支出）
     */
    @GetMapping
    public AjaxResult getAllCategories() {
        List<Map<String, Object>> allCategories = userCategoryService.getAllCategories();
        return success(allCategories);
    }
}
